import {
	RouterMount,
	createRouter
} from 'uni-simple-router';

// 自定义路由拦截白名单
const WHILE_LIST = ['/pages/login'];

const router = createRouter({
	platform: process.env.VUE_APP_PLATFORM,
	routes: [...ROUTES]
});
//全局路由前置守卫
router.beforeEach((to, from, next) => {

	if (WHILE_LIST.includes(to.path)) {
		next();
		return;
	}

	const token = uni.getStorageSync('token');

	if (token == '') {
		next('/pages/login');
		return // 拦截路由，不执行next
	} else {
		next();
	}

});
// 全局路由后置守卫
router.afterEach((to, from) => {})

export {
	router,
	RouterMount
}
